# Methods added to this helper will be available to all templates in the application.
module ApplicationHelper

  def has_photo_du_jour
    img = Image.last
    if img.nil? then
      true
    else
      false
    end
  end

  def photo_du_jour
    img = Image.last
    if img then
      "<img src='#{image_content_url(img, :width => 300, :height => 200, :fit_width => true)}' alt='#{img.name}' />"
    end
  end



  def image_content_url(image, options = {})
    options[:id] = image
    if options[:fit_width] then
      "#{resource_image_width_url(options)}"
    else
      "#{resource_image_url(options)}"
    end
  end

  def content_post (post)
    content = h(post.body)
    content = content.gsub(/\[p\]/, "<p>")
    content = content.gsub(/\[\/p\]/, "</p>")
    content = content.gsub(/\n/, "<br />")
    content = content.gsub(/\[ul\]/, "<ul>")
    content = content.gsub(/\[\/ul\]/, "</ul>")
    content = content.gsub(/\[ol\]/, "<ol>")
    content = content.gsub(/\[\/ol\]/, "</ol>")
    content = content.gsub(/\[li\]/, "<li>")
    content = content.gsub(/\[\/li\]/, "</li>")
    content = content.gsub(/\[([a-z0-9_]+)\]/, '<img src="/resource/img.true.150.\1.100.jpg" />')
  end
end
